package com.csxy.systemmanager.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csxy.systemmanager.dao.GoodDao;
import com.csxy.systemmanager.entity.Good;
import com.csxy.systemmanager.service.GoodService;
import org.springframework.stereotype.Service;

/**
 * (Good)表服务实现类
 *
 * @author makejava
 * @since 2024-06-15 15:15:30
 */
@Service("goodsService")
public class GoodServiceImpl extends ServiceImpl<GoodDao, Good> implements GoodService {

    @Override
    public Page<Good> listByPage(Integer current, Integer size, String query) {
        Page<Good> page = new Page<>(current, size);

        // 创建一个查询条件
        LambdaQueryWrapper<Good> wrapper = new LambdaQueryWrapper<>();

        // 如果查询条件不为空，添加模糊查询条件
        if (!StringUtils.isEmpty(query)) {
            wrapper.like(Good::getShopName, query);
        }

        // 添加按id降序排序
        wrapper.orderByDesc(Good::getShopId);

        // 执行查询
        return this.baseMapper.selectPage(page, wrapper);
    }
}

